package com.leeh.jsontest;

import android.app.Dialog;
import android.content.Context;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

/**
 * Created by Liheng on 2017-04-16.
 */

public class CourseDetailDialog extends Dialog {
    private Window window;
    private Context context;
    private TextView txtDialogContent;

    public CourseDetailDialog(Context context) {
        super(context);
        this.context = context;

    }

    public void showDialog(String content, int layoutResID, int x, int y) {
        setContentView(layoutResID);
        windowDeploy(x, y);
        txtDialogContent = (TextView) findViewById(R.id.dialog_content_textView);
        txtDialogContent.setText(content);
        //设置触摸对话框意外的地方取消对话框
        setCanceledOnTouchOutside(true);
        show();
    }

    //设置窗口显示
    public void windowDeploy(int x, int y) {
        window = getWindow(); //得到对话框
        window.setWindowAnimations(R.style.dialogWindowAnim); //设置窗口弹出动画
        window.setBackgroundDrawableResource(R.color.vifrification); //设置对话框背景为透明
        WindowManager.LayoutParams wl = window.getAttributes();
        //根据x，y坐标设置窗口需要显示的位置
        wl.x = x; //x小于0左移，大于0右移
        wl.y = y; //y小于0上移，大于0下移
        window.setAttributes(wl);
    }

}
